﻿
namespace Service
{
    using Data.Repository;
    using System.Linq;
	using System.Collections.Generic;

    public class ProductTagService : IProductTagService
    {
        private IProductTagRepository _productTagRepository;

        #region IProductTagService Members

        /// <summary>
        /// create new ProductTag
        /// </summary>
        /// <param name="theNewProductTag">the new ProductTag instance</param>
        /// <returns>the new ProductTag's ID</returns>
        public int CreateNewProductTag(Data.Entity.ProductTag theNewProductTag)
        {
            if (theNewProductTag == null)
            {
                return 0;
            }

            if (_productTagRepository == null)
            {
                _productTagRepository = new ProductTagRepository();
            }

            return _productTagRepository.CreateNewProductTag(theNewProductTag);
        }

        public int DeleteProductTag(int id)
        {
            if (id <= 0)
            {
                return 0;
            }

            if (_productTagRepository == null)
            {
                _productTagRepository = new ProductTagRepository();
            }

            return _productTagRepository.DeleteProductTag(id);
        }

		public IList<Data.Entity.ProductTag> GetProductTagByLanguage(int languageID)
        {
			if(languageID <= 0)
			{
				return null;
			}

            if (_productTagRepository == null)
            {
                _productTagRepository = new ProductTagRepository();
            }

            return _productTagRepository.GetProductTagByLanguage(languageID);
        }

		public Data.Entity.ProductTag GetTheProductTag(int id)
		{
			if(id <= 0)
			{
				return null;
			}

			if(_productTagRepository == null)
			{
				_productTagRepository = new ProductTagRepository();
			}

			return _productTagRepository.GetTheProductTag(id);
		}

		public int PlusOrMinus1ProductCount(int theProductTagID, int pn1)
		{
			if(theProductTagID <= 0)
			{
				return -1;
			}

			if(pn1 == 1 || pn1 == -1)
			{
				if(_productTagRepository == null)
				{
					_productTagRepository = new ProductTagRepository();
				}

				return _productTagRepository.PlusOrMinus1ProductCount(theProductTagID, pn1);
			}
			else
			{
				return -1;
			}
		}

		#endregion
	}
}
